<template>
  <div id="app">
    <Topbar :key="topbarkey"></Topbar>
    <Header></Header>
    <router-view @updateKey="updateKeyFn" />
    <Footer></Footer>
    <Login v-show="isShowLoginModal"></Login>
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>
<script>
import Topbar from "./components/Topbar.vue";
import Header from "./components/Hearder.vue";
import Footer from "./components/Footer.vue";
import Login from "./components/Login.vue";
import Toast from "./components/Toast.vue";
import { JingPinAPI, ReMenAPI } from "./request/api";
import { mapState } from "vuex";
export default {
  data() {
    return {
      topbarkey: 0,
    };
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  methods: {
    updateKeyFn() {
      this.topbarkey++;
    },
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        console.log("地址变化了", newVal, oldVal);
        // 如果旧地址为/就不需要重载
        if (oldVal != "/") {
          this.topbarkey++;
        }
      },
    },
  },
  async created() {
    console.log("环境变量为：", process.env.VUE_APP_MY_NAME);
    // axios
    //   .get("http://kumanxuan1.f3322.net:8881/cms/products/recommend")
    //   .then((res) => {
    //     console.log("请求结果为：", res);
    //   });
    // JingPinAPI().then((res) => {
    //   console.log("请求数据2", res);
    // });
    // ReMenAPI().then((res) => {
    //   console.log("请求数据3", res);
    // });
    // let res = await JingPinAPI();
    // console.log(1, res);
    // console.log(2);
    // let res2 = await ReMenAPI();
    // console.log(3, res2);
    // console.log(4);
  },
};
</script>
<style lang="less" scoped>
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
